﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>倒计时载入页面</title>
    <script type="text/javascript" language="JavaScript">
        // 获取当前时间
        startday = new Date();
        clockStart = startday.getTime();
        
        function initStopwatch(){
            let myTime = new Date();
            let timeNow = myTime.getTime();
            let timeDiff = timeNow - clockStart;    // 获取间隔时间
            this.diffSecs = timeDiff / 1000;    // 因为时间以毫秒为单位
            return this.diffSecs;   // 返回间隔秒数
        }
        
        function getSecs(){
            let mySecs = initStopwatch();
            let mySecs1 = ""+mySecs;
            //以倒计时方式显示时间
            mySecs1= 10 - eval(mySecs1.substring(0,mySecs1.indexOf("."))) + "秒";
            document.form1.timespent.value = mySecs1;
            window.setTimeout('getSecs()',1000);
        }
    </script>
</head>
<body bgcolor="#ffffff" onLoad="window.setTimeout('getSecs()',1)">
<center>
    10秒后将加载页面:
    <form name=form1><input size=9 name=timespent></form>
</center>
</body>
</html>